package com.duduli.li;

import com.duduli.li.mapper.JdMapper;
import com.duduli.li.po.ProductPrice;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;
import java.util.List;

public class InsertProducPrice {
    public void getAllProductId() throws IOException {
        Reader reader = Resources.getResourceAsReader("config/conf.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader);
        SqlSession sqlSession = factory.openSession();
        JdMapper mapper =sqlSession.getMapper(JdMapper.class);
        GetWebProductPrice g = new GetWebProductPrice();
        List<ProductPrice> list = g.getPrice();
        for (ProductPrice p : list){
            System.out.println(p.toString());
            mapper.insertProductPrice(p);
            sqlSession.commit();
        }
        sqlSession.close();
    }

    public static void main(String[] args) throws IOException {
        InsertProducPrice ipp = new InsertProducPrice();
        ipp.getAllProductId();
    }
}
